home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / xsharp21.zip / MOVEOBJ.C < prev    next >
Text File  |  1992-06-09  |  3KB  |  85 lines

  1. /* Rotates and moves polygon-based objects (only balls, at the moment). */
  2. #include "polygon.h"
  3.  
  4. #define X_BALL_MOVE 1.0
  5. #define Y_BALL_MOVE 1.0
  6. #define Z_BALL_MOVE 20.0
  7.  
  8. void RotateAndMoveBall(PObject * ObjectToMove)
  9. {
  10.    /* Change the spin axis from X to Y or Y to X if requested by the user */
  11.    if (BallEvent & FLIP_SPIN_AXIS) {
  12.       if (ObjectToMove->Rotate.RotateX != 0) {
  13.          ObjectToMove->Rotate.RotateX = 0;
  14.          ObjectToMove->Rotate.RotateY = 100; /* 10 degree Y rotations */
  15.       } else if (ObjectToMove->Rotate.RotateY != 0) {
  16.          ObjectToMove->Rotate.RotateY = 0;
  17.          ObjectToMove->Rotate.RotateZ = 50; /* 5 degree Z rotations */
  18.       } else {
  19.          ObjectToMove->Rotate.RotateZ = 0;
  20.          ObjectToMove->Rotate.RotateX = 75; /* 1.6 degree X rotations */
  21.       }
  22.       BallEvent &= ~FLIP_SPIN_AXIS;
  23.    }
  24.  
  25.    /* Rotate the ball as needed */
  26.    if (--ObjectToMove->RDelayCount == 0) {   /* rotate */
  27.       ObjectToMove->RDelayCount = ObjectToMove->RDelayCountBase;
  28.       if (ObjectToMove->Rotate.RotateX != 0)
  29.          AppendRotationX(ObjectToMove->XformToWorld,
  30.                ObjectToMove->Rotate.RotateX);
  31.       if (ObjectToMove->Rotate.RotateY != 0)
  32.          AppendRotationY(ObjectToMove->XformToWorld,
  33.                ObjectToMove->Rotate.RotateY);
  34.       if (ObjectToMove->Rotate.RotateZ != 0)
  35.          AppendRotationZ(ObjectToMove->XformToWorld,
  36.                ObjectToMove->Rotate.RotateZ);
  37.       ObjectToMove->RecalcXform = 1;
  38.    }
  39.  
  40.    /* Move the ball in response to recorded key events */
  41.    if (BallEvent & MOVE_LEFT) {
  42.       if (ObjectToMove->XformToWorld[0][3] > DOUBLE_TO_FIXED(-15000.0)) {
  43.          ObjectToMove->XformToWorld[0][3] -= DOUBLE_TO_FIXED(X_BALL_MOVE);
  44.          ObjectToMove->RecalcXform = 1;
  45.       }
  46.       BallEvent &= ~MOVE_LEFT;
  47.    }
  48.    if (BallEvent & MOVE_RIGHT) {
  49.       if (ObjectToMove->XformToWorld[0][3] < DOUBLE_TO_FIXED(15000.0)) {
  50.          ObjectToMove->XformToWorld[0][3] += DOUBLE_TO_FIXED(X_BALL_MOVE);
  51.          ObjectToMove->RecalcXform = 1;
  52.       }
  53.       BallEvent &= ~MOVE_RIGHT;
  54.    }
  55.    if (BallEvent & MOVE_UP) {
  56.       if (ObjectToMove->XformToWorld[1][3] < DOUBLE_TO_FIXED(15000.0)) {
  57.          ObjectToMove->XformToWorld[1][3] += DOUBLE_TO_FIXED(Y_BALL_MOVE);
  58.          ObjectToMove->RecalcXform = 1;
  59.       }
  60.       BallEvent &= ~MOVE_UP;
  61.    }
  62.    if (BallEvent & MOVE_DOWN) {
  63.       if (ObjectToMove->XformToWorld[1][3] > DOUBLE_TO_FIXED(-15000.0)) {
  64.          ObjectToMove->XformToWorld[1][3] -= DOUBLE_TO_FIXED(Y_BALL_MOVE);
  65.          ObjectToMove->RecalcXform = 1;
  66.       }
  67.       BallEvent &= ~MOVE_DOWN;
  68.    }
  69.    if (BallEvent & MOVE_TOWARD) {
  70.       if (ObjectToMove->XformToWorld[2][3] < DOUBLE_TO_FIXED(-100.0)) {
  71.          ObjectToMove->XformToWorld[2][3] += DOUBLE_TO_FIXED(Z_BALL_MOVE);
  72.          ObjectToMove->RecalcXform = 1;
  73.       }
  74.       BallEvent &= ~MOVE_TOWARD;
  75.    }
  76.    if (BallEvent & MOVE_AWAY) {
  77.       if (ObjectToMove->XformToWorld[2][3] > DOUBLE_TO_FIXED(-15000.0)) {
  78.          ObjectToMove->XformToWorld[2][3] -= DOUBLE_TO_FIXED(Z_BALL_MOVE);
  79.          ObjectToMove->RecalcXform = 1;
  80.       }
  81.       BallEvent &= ~MOVE_AWAY;
  82.    }
  83. }
  84.  
  85.